#include <stdio.h>
//
// for off_t---lseek() , mode_t---umask(),open()
#include <sys/types.h>

// for umask(), open()
#include <sys/stat.h>
// for open()
#include <fcntl.h>

//for lseek(),close(),read(),write();
#include <unistd.h>

#include <string.h>

int main(int argc, char *argv[]){
    umask(0);
    //open("log.txt", O_WRONLY);
    //open("log.txt", O_WRONLY | O_CREAT);
    
    /*file description*/
    //int fd1 = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0666);
    int fd1 = open(argv[1], O_WRONLY | O_CREAT | O_APPEND, 0666);
    if( -1 != fd1){
        printf("fd1 : %d\n",fd1);
    }
    else { perror("open:"); return 1;}

    const char *buffer = "hello file";
    write(fd1, buffer, strlen(buffer));

    close(fd1);

    return 0;
}
